Skip to content

Conversation

@taisukeoe
Copy link
Contributor

@taisukeoe taisukeoe commented Apr 12, 2025

Context

This PR fixes a bug not to respect the following symbolic links under .roo/rules directory.

  • A symbolic link to another symbolic link
  • A symbolic link to a directory

Implementation

Enhance readTextFilesFromDirectory function with two helper functions which are called recursively:

  • resolveSymLink
  • resolveDirectoryEntry

So that recursive symbolic link or directory structure can be respected.
MAX_DEPTH = 5 is also set to avoid cyclic symbolic links and infinite loops.

Screenshots

Given this rules directory structure

.roo % tree
.
├── linked-dir
│   └── missed.txt
├── nested-link.txt
├── nested-symlink -> nested-link.txt
├── rules
│   ├── dir-symlink -> ../linked-dir
│   ├── link-symlink -> ../nested-symlink

Preview System Prompt in RooCode project will look like:

before after
スクリーンショット 2025-04-12 12 00 58 スクリーンショット 2025-04-12 12 01 31

How to Test

As described in ScreenShots section.

Get in Touch

I'm in the RooCode Discord Server as @taisukeoe. Please feel free to contact me if any.


Important

Fixes bug in readTextFilesFromDirectory to handle symbolic links to directories and other symbolic links in .roo/rules, with tests added.

  • Behavior:
    • Fixes bug in readTextFilesFromDirectory to handle symbolic links to directories and other symbolic links in .roo/rules.
    • Sets MAX_DEPTH = 5 to prevent cyclic symbolic links and infinite loops.
  • Functions:
    • Adds resolveSymLink and resolveDirectoryEntry to recursively resolve symbolic links and directories in custom-instructions.ts.
  • Tests:
    • Updates custom-instructions.test.ts to test new symbolic link handling behavior.

This description was created by Ellipsis for 718c356. It will automatically update as commits are pushed.

@changeset-bot
Copy link

changeset-bot bot commented Apr 12, 2025

🦋 Changeset detected

Latest commit: 718c356

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
roo-cline Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@taisukeoe taisukeoe marked this pull request as ready for review April 12, 2025 03:20
@taisukeoe taisukeoe requested review from cte and mrubens as code owners April 12, 2025 03:20
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. bug Something isn't working labels Apr 12, 2025
return
}

const fullPath = path.resolve(entry.parentPath || dirPath, entry.name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code relies on a non-standard parentPath property on Dirent objects. parentPath isn’t part of the standard Dirent interface, which could lead to inconsistencies outside of your tests. Consider passing the directory path explicitly instead.

Suggested change
const fullPath = path.resolve(entry.parentPath || dirPath, entry.name)
const fullPath = path.resolve(dirPath, entry.name)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parentPath should be used. ref: #2405 (comment)

const resolvedTarget = path.resolve(path.dirname(fullPath), linkTarget)

// Check if the target is a file
const stats = await fs.stat(resolvedTarget)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using fs.stat to check if the target is a symlink may be ineffective since fs.stat follows symlinks. To accurately detect a nested symlink, consider using fs.lstat instead.

Suggested change
const stats = await fs.stat(resolvedTarget)
const stats = await fs.lstat(resolvedTarget)

Copy link
Collaborator

@mrubens mrubens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Thank you for cleaning this up 🙏

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Apr 12, 2025
@mrubens mrubens merged commit e453690 into RooCodeInc:main Apr 12, 2025
28 checks passed
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Apr 12, 2025
@taisukeoe taisukeoe deleted the fix/symbolic-link-dir branch April 12, 2025 03:34
@taisukeoe
Copy link
Contributor Author

Thank you for prompt merge! Looking forward to the upcoming release 🤞

JorkeyLiu pushed a commit to JorkeyLiu/Roo-Code that referenced this pull request Apr 13, 2025
…y or another symbolic link (RooCodeInc#2513)

* read symbolic linked dir and files recursively

* add symlinked dir and nested symlink test case for custom-instructions

* enhance comments

* add changeset
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working lgtm This PR has been approved by a maintainer size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants